home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / clp.exe / CLPARSER.HDR < prev    next >
Encoding:
Text File  |  1992-09-07  |  11.9 KB  |  224 lines

  1. { ========================================================================== }
  2. {  Unit: CLPARSER (formerly PARSER) Command_Line_Parser                      }
  3. { ========================================================================== }
  4. {                                                                            }
  5. {                                                                            }
  6. {       !!!!  !!!!    !!!!!!                                                 }
  7. {      !!  !!  !!      !!  !!                                                }
  8. {     !!    !  !!      !!  !!  !!!!   !! !!!   !!!!!   !!!!!  !! !!!         }
  9. {     !!       !!      !!  !!     !!   !!! !! !!   !! !!   !!  !!! !!        }
  10. {     !!       !!      !!!!!   !!!!!   !!  !!  !!!    !!!!!!!  !!  !!        }
  11. {     !!    !  !!   !  !!     !!  !!   !!        !!!  !!       !!            }
  12. {      !!  !!  !!  !!  !!     !!  !!   !!     !!   !! !!   !!  !!            }
  13. {       !!!!  !!!!!!! !!!!     !!! !! !!!!     !!!!!   !!!!!  !!!!           }
  14. {                                                                            }
  15. {                                                                            }
  16. { ========================================================================== }
  17. {                                                                            }
  18. {    Description: Parser provides access to commandline arguments and        }
  19. {                 switches by separating them into seperate arrays.          }
  20. {                                                                            }
  21. {    Modification History:                                                   }
  22. {                                                                            }
  23. {      PARSER     04/07/89   Version 1.0                                     }
  24. {                                                                            }
  25. {      OPARSER    04/14/89   Version 1.1  (TEST OOPS style OBJECT unit)      }
  26. {                                                                            }
  27. {      CLPARSER   06/26/89   Version 2.0  (OOPS OBJECT unit)                 }
  28. {                                                                            }
  29. {      CLPARSER   07/26/89   Version 2.1                                     }
  30. {                                                                            }
  31. {                            Fixed a bug in the Argument.Find method         }
  32. {                            that allowed a target string longer than        }
  33. {                            the item string to match if the first           }
  34. {                            part of the target matched the item.            }
  35. {                                                                            }
  36. {                            Added the PFile type.  This is a parameter      }
  37. {                            file parser that fills the list with            }
  38. {                            valid parameters from the file. Comments        }
  39. {                            are definable and skipped.  White space         }
  40. {                            (tabs, spaces and blank lines) is ignored,      }
  41. {                            also.                                           }
  42. {                                                                            }
  43. {                            This is the first version released to           }
  44. {                            bulletin boards. (TP5.5)                        }
  45. {                                                                            }
  46. {      CLPARSER   08/19/89   Version 2.11                                    }
  47. {                                                                            }
  48. {                            Removed external library references and comp-   }
  49. {                            iled the shareware version as overlay-able.     }
  50. {                                                                            }
  51. {      CLPARSER   10/01/90   Version 3.0                                     }
  52. {                                                                            }
  53. {                            Re-implemented the list as entirely heap        }
  54. {                            resident.  When the object is collapsed it will }
  55. {                            now reclaim all heap memory used.  I found that }
  56. {                            in many cases the amount of heap stolen was TOO }
  57. {                            MUCH!                                           }
  58. {                                                                            }
  59. {      CLPARSER   04/06/91   Version 3.1                                     }
  60. {                                                                            }
  61. {                            This version is compatible with TP 6.0.         }
  62. {                            Several fundamental changes were made to this   }
  63. {                            unit which changed the programmer interface.    }
  64. {                                                                            }
  65. {                            1. Automatic variables have been dropped.  You  }
  66. {                               must declare and initialize all objects used }
  67. {                               in your own source.                          }
  68. {                                                                            }
  69. {                            2. Typed pointers to the object have been added }
  70. {                               to allow dynamic allocation of objects.      }
  71. {                                                                            }
  72. {                            3. The ERASE method has been renamed DONE. This }
  73. {                               aligns CLPARSER with "standard" nomenclature }
  74. {                               used by OPro and TVision.                    }
  75. {                                                                            }
  76. {                            ie.                                             }
  77. {                                                                            }
  78. {                               Var                                          }
  79. {                                   pArg, pSw : pArgument;                   }
  80. {                                                                            }
  81. {                               begin                                        }
  82. {                                   pArg := New( pArgument, Init(            }
  83. {                                       NormalChars-Switches));              }
  84. {                                   pSw := New( pArgument, Init(Switches));  }
  85. {                                                                            }
  86. {                                   if pArg^.Count = ......                  }
  87. {                                   ....                                     }
  88. {                                   ....                                     }
  89. {                                                                            }
  90. {                                   Dispose( pArg, Done );                   }
  91. {                                   Dispose( pSw, Done );                    }
  92. {                               end;                                         }
  93. {                                                                            }
  94. {                            4. The HELP object has been added.              }
  95. {                                                                            }
  96. {                                                                            }
  97. {      CLPARSER   02/29/92   Version 3.2                                     }
  98. {                                                                            }
  99. {                            This version was modified to include a pointer  }
  100. {                            to a CARGO area.  The cargo can be any thing.   }
  101. {                            The ItemRecord definition now includes 2 new    }
  102. {                            declarations: Cargo and CargoLen.  Cargo is a   }
  103. {                            pointer and CargoLen is a long integer.         }
  104. {                                                                            }
  105. { ========================================================================== }
  106. {               Copyright (c) 1989, 1992 by Greg L. Truesdell                }
  107. {                            All Rights Reserved                             }
  108. { ========================================================================== }
  109. {*}                {.A-,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V-}                  {*}
  110. { ========================================================================== }
  111. Unit CLParser;
  112.  
  113. { ========================================================================== }
  114.                                   INTERFACE
  115. { ========================================================================== }
  116.  
  117. Type
  118.     CharSet = Set of Char;
  119.  
  120.     { argument record }
  121.  
  122.     ItemRecordP = ^ItemRecord;
  123.     ItemRecord = Record
  124.  
  125.         Item        :^String;       { parsed item String }
  126.         ItemLen     : Byte;         { length + 2 of item String }
  127.         Posn        : LongInt;      { position }
  128.         Cargo       : Pointer;      { data record pointer }
  129.         CargoLen    : LongInt;      { size of data record }
  130.         NextItem    : ItemRecordP;  { pointer to the next node in list }
  131.         PrevItem    : ItemRecordP;  { pointer to previous node in list }
  132.  
  133.     end;
  134.  
  135.     { list is the data structure }
  136.  
  137.     pClpList = ^clpList;
  138.     clpList = object
  139.  
  140.         firstitem   : ItemRecordP;  { pointer to first record in list }
  141.         currentitem : ItemRecordP;  { pointer to current record in list }
  142.         lastitem    : ItemRecordP;  { pointer to last record in list}
  143.         items       : Word;         { number of items in the list }
  144.         index       : Word;         { current item number }
  145.  
  146.         Constructor Init;
  147.         Destructor  Done;
  148.         Function    Add( add_item: String; locn: LongInt ) : Boolean;
  149.         Function    AddCargo( Add_Item: String; Locn : LongInt;
  150.                         pCargo : Pointer; CargoSize: Word ) : Boolean;
  151.         Function    Next : String;
  152.         Function    NextCargo( var pCargo : Pointer; var CargoSize : LongInt ) : String;
  153.         Function    Prev : String;
  154.         Function    PrevCargo( var pCargo : Pointer; var CargoSize : LongInt ) : String;
  155.         Function    Count : Word;
  156.         Function    Position : LongInt;
  157.         Procedure   Reset;
  158.  
  159.     end;
  160.  
  161.     { help is a list of help lines }
  162.     pHelp = ^Help;
  163.     Help = object(clpList)
  164.  
  165.         ScreenLines : Byte;
  166.         LineCount   : Byte;
  167.  
  168.         Constructor Init( nLines : Byte );
  169.         Function    ReadFile( filename : String ) : Boolean;
  170.         Procedure   Display;
  171.  
  172.     end;
  173.  
  174.     { argument is a list of arguments }
  175.  
  176.     pArgument = ^Argument;
  177.     Argument = object(clpList)
  178.  
  179.         more    : Boolean;
  180.  
  181.         Constructor Init( LegalChars: CharSet );
  182.         Function    Find( target : String ): String;
  183.         Function    Overflow: Boolean;
  184.  
  185.     end;
  186.  
  187.     { Environ is a list of environment variables }
  188.  
  189.     pEnviron = ^Environ;
  190.     Environ = object(Argument)
  191.  
  192.         Constructor Init;
  193.  
  194.     end;
  195.  
  196.     { wild is a special list of filenames }
  197.  
  198.     pWild = ^Wild;
  199.     Wild = object(argument)
  200.  
  201.         Constructor Init( filemask: String; attributes: Word );
  202.  
  203.     end;
  204.  
  205.     { pfile is a special list of parameter file entries }
  206.     pPFile = ^PFile;
  207.     PFile = object(argument)
  208.  
  209.         Constructor Init( filename: String; comment: CharSet );
  210.  
  211.     end;
  212.  
  213. Const
  214.  
  215.     { default argument triggers }
  216.     Switches    : CharSet = ['/','-','+'];  { Set of switch Characters }
  217.     NormalChars : CharSet = [#32..#127];    { Set of normal Chars }
  218.     CmdTail     : String  = '';
  219.  
  220. { ========================================================================== }
  221.                                 IMPLEMENTATION
  222. { ========================================================================== }
  223.  
  224.